#encoding='utf-8'
import os

from src.code.data_process import Data_Proccess
from src.code.svm import Algorithm_Run

music_audio_dir='../../doc/data/test/mp3/'
wav_save_dir='../../doc/data/test/wav/'
model_file_path = '../../doc/model/music_model.pkl'

def model_train():
    algorithm_run = Algorithm_Run()
    algorithm_run.fit_dump_model(train_percentage=0.9, fold=100)

def model_run():
    musics = ['Beautiful-Orkidea.mp3','Lasse Lindh - Run To You.mp3','Maize - I Like You-浪漫.mp3','孙燕姿 - 我也很想他 - 怀旧.mp3']
    data_process=Data_Proccess()
    algorithm_run = Algorithm_Run()

    is_exists=os.path.exists(model_file_path)
    if not is_exists:
        model_train()

    for music in musics:
        old_file=music_audio_dir+music
        new_file=wav_save_dir+music.replace('mp3','wav')
        music_feature=data_process.extract(old_file,new_file)
        clf=algorithm_run.load_model()
        label=algorithm_run.fetch_predict_label(clf, music_feature)
        print('预测标签为：%s' % label)

def model_select():
    algorithm_run = Algorithm_Run()
    algorithm_run.cross_validation()


model_run()

    